﻿namespace Arbalest.Models
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data.Objects.DataClasses;
    using System.Runtime.Serialization;
    using System.Xml.Serialization;
    using Arbalest.Web.Controllers;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class Item 
    {
        public long Id { get; set; }

        [Required(ErrorMessage = "Company name is required")]
        [DisplayName("Company Name")]
        [UIHint("Company")]
        public long CompanyId { get; set; }

        [Required(ErrorMessage="Code is required")]
        [DisplayName("Code")]
        public string Code { get; set; }

        [DisplayName("Name")]
        public string Name { get; set; }
        
        [DisplayName("Description")]
        public string Description { get; set; }


        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        [DisplayName("Date")]
        [Required(ErrorMessage="Date is required")]
        public DateTime? CreatedDateTime { get; set; }

        public Company Company
        {
            get;
            set;
        }
    }

    public class StorageItem
    {
        public long Id { get; set; }

        [Required(ErrorMessage = "Item name is required")]
        [DisplayName("Item Name")]
        public long ItemId { get; set; }

        [Required(ErrorMessage = "Storage location is required")]
        [DisplayName("Storage Location")]
        public long StorageLocationId { get; set; }

        [Required(ErrorMessage = "Quantity is required")]
        [DisplayName("Quantity")]
        public decimal Quantity { get; set; }

        [Required(ErrorMessage = "Unit is required")]
        [DisplayName("Unit")]
        public long UnitOfMeasureId { get; set; }

        [DisplayName("Date")]
        [DisplayFormat(DataFormatString = "{0:d}")]
        [Required(ErrorMessage = "Date is required")]
        public DateTime? CreatedDateTime { get; set; }

    }

    public class StorageLocationType
    {
        public long Id { get; set; }

        [Required(ErrorMessage = "Code is required")]
        [DisplayName("Code")]
        public string Code { get; set; }

        [DisplayName("Name")]
        public string Name { get; set; }

        [DisplayName("Description")]
        public string Description { get; set; }

        [DisplayName("Date")]
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        [Required(ErrorMessage = "Date cannot be undefined.")]
        public DateTime? CreatedDateTime { get; set; }


        public ICollection<StorageLocation> StorageLocations
        {
            get
            {
                DataStore ds = new DataStore();
                return ds.GetList<StorageLocation>().ToList();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

    }

    public class StorageLocation
    {
        public long Id { get; set; }

        [DisplayName("Company Name")]
        [UIHint("Company")]
        [Required(ErrorMessage = "Company is required")]
        public long? CompanyId { get; set; }

        [Required(ErrorMessage = "Storage location type is required")]
        [DisplayName("Storage Location Type")]
        [UIHint("StorageLocationType")]
        public long StorageLocationTypeId { get; set; }

        [DisplayName("Parent Storage Location")]
        public long? ParentStorageLocationId { get; set; }

        [Required(ErrorMessage = "Code is required")]
        [DisplayName("Code")]
        public string Code { get; set; }

        [DisplayName("Name")]
        public string Name { get; set; }

        [DisplayName("Description")]
        public string Description { get; set; }

        [DisplayName("Date")]
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        [Required(ErrorMessage = "Date is required")]
        public DateTime? CreatedDateTime { get; set; }

        public Company Company
        {
            get;
            set;
        }

        [DisplayName("Parent Loc")]
        public StorageLocation StorageLocationParent
        {
            get;
            set;
        }
        public StorageLocationType StorageLocationType
        {
            get;
            set;
        }

        //public ICollection<StorageLocation> StorageLocations
        //{
        //    get
        //    {
        //        DataStore ds = new DataStore();
        //        return ds.GetList<StorageLocation>().ToList();
        //    }
        //    set
        //    {
        //        throw new NotImplementedException();
        //    }
        //}
    }

    public class UnitOfMeasure
    {
        public long Id { get; set; }

        [DisplayName("Company Name")]
        public long CompanyId { get; set; }

        [Required(ErrorMessage = "Code is required")]
        [DisplayName("Code")]
        public string Code { get; set; }

        [DisplayName("Name")]
        public string Name { get; set; }

        [DisplayName("Description")]
        public string Description { get; set; }

        [DisplayName("Date")]
        [DisplayFormat(DataFormatString = "{0:d}")]
        [Required(ErrorMessage = "Date is required")]
        public DateTime? CreatedDateTime { get; set; }
    }
}